using System;
using System.Drawing;
using System.Xml.Serialization;

namespace DataAccessLayer
{
    [Serializable]
    public struct EditorRect
    {
        [XmlAttribute]
        public int X { get; set; }

        [XmlAttribute]
        public int Y { get; set; }

        [XmlAttribute]
        public int Width { get; set; }

        [XmlAttribute]
        public int Height { get; set; }

        [XmlIgnore]
        public Point Location
        {
            get { return new Point(X, Y); }
            set
            {
                X = value.X;
                Y = value.Y;
            }
        }

        [XmlIgnore]
        public Size Size
        {
            get { return new Size(Width, Height); }
            set
            {
                Width = value.Width;
                Height = value.Height;
            }
        }

        [XmlIgnore]
        public static EditorRect Empty
        {
            get { return new EditorRect(0, 0, 0, 0); }
        }

        public EditorRect(int x, int y, int width, int height) : this()
        {
            X = x;
            Y = y;
            Width = width;
            Height = height;
        }

        public EditorRect(Point location, Size size) : this()
        {
            Location = location;
            Size = size;
        }

        public EditorRect(Rectangle rect) : this()
        {
            Location = rect.Location;
            Size = rect.Size;
        }

        public static implicit operator Rectangle(EditorRect rect)
        {
            return new Rectangle(rect.Location, rect.Size);
        }

        public static implicit operator EditorRect(Rectangle rect)
        {
            return new EditorRect(rect);
        }

        public void SetRectangle(int x, int y, int width, int height)
        {
            X = x;
            Y = y;
            Width = width;
            Height = height;
        }
    }
}